{% extends "sentry/bases/auth.html" %}

{% load crispy_forms_tags %}
{% load i18n %}
{% load sentry_avatars %}

{% block title %}{% trans "Authorize Application" %} | {{ block.super }}{% endblock %}

{% block auth_main %}
  <form class="form-stacked" action="." method="post" autocomplete="off">
    {% csrf_token %}

    <div>
      <p><strong>{{ application.name }}</strong> is requesting access to your Sentry account linked to ({{ user.username }}). Granting this access will give {{ application.name }} access to your account details, including:</p>
      <ul>
        <li>Your name</li>
        <li>Your email address</li>
      </ul>
      <p>
        {% if organization_options|length != 1 %}
        <!-- If application needs user level access or it's org level access and user has multiple orgs -->
          {{ application.name }} will also have the following permissions to your Sentry organizations:
        {% else %}
        <!-- If user only has one org and application requires org level access, choose that org by default -->
          {{ application.name }} will also have the following permissions to your Sentry organization <strong>{{organization_options.0.name}}</strong>:
          <input type="hidden" name="selected_organization_id" value="{{ organization_options.0.id }}">
        {% endif %}
      </p>
      <ul>
        {% for permission in permissions %}
          <li>{{ permission }}</li>
        {% endfor %}
      </ul>

      {% if organization_options|length > 1 %}
        <!-- If there are multiple organizations and application requires org level access, show the selector -->
        <label for="organization">Select one of your sentry organizations to grant access to:</label>
        <select name="selected_organization_id" id="organization_id">
            {% for organization in organization_options %}
                <option value="{{ organization.id }}">{{ organization.name }}</option>
            {% endfor %}
        </select>
      {% endif %}
      {% if application.terms_url or application.privacy_url %}
        <p><small>
          {% if application.terms_url %}
            <a href="{{ application.terms_url }}">Terms of Use</a>
            {% if application.privacy_url %} &mdash; {% endif %}
          {% endif %}
          {% if application.privacy_url %}
            <a href="{{ application.privacy_url }}">Privacy Policy</a>
          {% endif %}
        </small></p>
      {% endif %}
    </div>

    <div class="auth-footer">
      <button type="submit" class="btn btn-primary" name="op" value="approve">{% trans "Approve" %}</button>
      <button type="submit" class="btn btn-danger" name="op" value="deny">{% trans "Deny" %}</button>
    </div>
  </form>
{% endblock %}
